package com.yudaxian.bi.config;

import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import com.yudaxian.bi.model.entity.User;
import com.yudaxian.bi.model.enums.UserRoleEnum;
import com.yudaxian.bi.service.UserService;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: yudaxian
 * @Description: 获取权限合集
 * @DateTime: 2024/9/16 13:15
 **/
@Configuration
public class PermissionConfig implements StpInterface {

    @Resource
    private UserService userService;

    @Override
    public List<String> getPermissionList(Object o, String s) {
        return List.of();
    }

    @Override
    public List<String> getRoleList(Object o, String s) {
        long loginId = Long.parseLong(StpUtil.getLoginId().toString());
        User user = userService.getById(loginId);
        UserRoleEnum enumByCode = UserRoleEnum.getEnumByCode(user.getUserRole());
        return List.of(enumByCode.getValue());
    }
}
